package weaver.interfaces.cetc.duss.action;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.cetc.duss.utils.CetcUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2024-04-23
 * @Description: 内部调用审批表调用接口修改调入人部门
 * @ModifyLog:
 **/
public class WeaNbddspbAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>>WeaNbddspbAction>>>>>requestid=" + requestid);
        try {
            String url = "";
            JSONObject paramJson = new JSONObject();
            JSONArray datalist =new JSONArray();
            RecordSet rs = new RecordSet();
            rs.execute("select drbmbh,xm from " + tablename + " where requestid=?", requestid);
            rs.next();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("departmentcode", Util.null2String(rs.getString("drbmbh")));
            String xm = Util.null2String(rs.getString("xm"));
            jsonObject.put("loginid", CetcUtil.getLoginidById(xm));
            datalist.add(jsonObject);
            paramJson.put("datalist",datalist);
            JSONObject resultJson = CetcUtil.sendOKHttpRequest(paramJson.toJSONString(), url);
            String message = Util.null2String(resultJson.getString("message"));
            if (!"success".equals(message)) {
                String data = Util.null2String(resultJson.getString("data"));
                JSONObject dataJson = JSONObject.parseObject(data);
                int succcounts =Util.getIntValue(dataJson.getString("succcounts"));
                int totalcounts =Util.getIntValue(dataJson.getString("totalcounts"));
                 message =Util.null2String(dataJson.getString("message"));
                if(succcounts!=totalcounts){
                    requestInfo.getRequestManager().setMessageid("111111");
                    requestInfo.getRequestManager().setMessagecontent("Action接口异常:"+message);
                    return Action.FAILURE_AND_CONTINUE;
                }

            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}